//index.js
//获取应用实例
const app = getApp()
Page({
  data: {
    userName: '',
    passWord: ''
  },
  onLoad: function (options) {
    
  },
  // 获取输入账号
  userInput: function (e) {
    this.setData({
      userName: e.detail.value
    })
  },

  // 获取输入密码
  pwdInput: function (e) {
    this.setData({
      passWord: e.detail.value
    })
  },

  // 登录
  login: function () {
    if (this.data.userName.length == 0 || this.data.passWord.length == 0) {
      wx.showToast({
        title: '信息不能为空',
        icon: 'loading',
        duration: 2000
      })
    } else {
      // 这里修改成跳转的页面
      wx.request({
        url: 'https://haiyang.mynatapp.cc/api/auth', //url
        data: {
          "username": this.data.userName,
          "password": this.data.passWord
        },
        method: "POST",
        header: {
          'content-type': 'application/x-www-form-urlencoded',
          // 'Content-Type': 'application/json'
        },
        success: function (res) {
          wx.setStorageSync('key', res.data.data);
          wx.navigateTo({
            url: '../index/index'
          })
        },
        fail: function () {
          app.consoleLog("请求数据失败");
        },
        complete: function () {
          // complete 
        }
      })
    }
  }
})
